#include <FunctionsPluginOsg.h>
#include <EDesignerCore.h>
#include <OsgClassDataSource/NodeOsg.h>
//osg::ref_ptr<osg::Object> FunctionsPluginOsg::ObjectInspectorItemToOsgObjectPtr(ObjectInspectorItem *item)
//{
//    osg::ref_ptr<osg::Object> osgObjectPtr = NULL;
//    QSharedPointer<QObject> object_ptr = item->getObjectPtr();
//    OsgObjectQt* osg_object_qt_ptr = dynamic_cast<OsgObjectQt*>(object_ptr.data());
//    if(osg_object_qt_ptr != NULL)
//    {
//        osgObjectPtr = osg_object_qt_ptr->getObject();

//    }

//    return osgObjectPtr;
//}

//osg::ref_ptr<osg::Node> FunctionsPluginOsg::ObjectInspectorItemToOsgNodePtr(ObjectInspectorItem *item)
//{
//    osg::ref_ptr<osg::Node> osgNodePtr = NULL;
//    QSharedPointer<QObject> object_ptr = item->getObjectPtr();
//    OsgObjectQt* osg_object_qt_ptr = dynamic_cast<OsgObjectQt*>(object_ptr.data());
//    if(osg_object_qt_ptr != NULL)
//    {
//        //osgNodePtr = osg_object_qt_ptr->getObject();
//        osgNodePtr = dynamic_cast<osg::Node*>(osg_object_qt_ptr->getObject().get());
//    }

//    return osgNodePtr;
//}

void FunctionsPluginOsg::EDesignerCoreSimulationWaitUpdateEndAndStopSim()
{
    EDesignerCore::instance()->simulationWaitUpdateEndAndStopSim();
}

void FunctionsPluginOsg::EDesignerCoreSimulationStopWaitUpdateEnd()
{
    EDesignerCore::instance()->simulationstopWaitUpdateEnd();
}

//std::string FunctionsPluginOsg::getUiTypeString(osg::Object* osgObj)
//{
//    _type_string = typeid(*osgObj).name();
//    std::string _ui_type_string;
//    int pos1 = _type_string.find(":");
//    if (pos1 != std::string::npos)
//    {
//        _ui_type_string = _type_string.substr(pos1+2, _type_string.size()-1);
//    }
//    else
//    {
//        pos1 = _type_string.find(" ");
//        _ui_type_string = _type_string.substr(pos1+1, _type_string.size()-1);
//    }
//    return _ui_type_string;
//}

osg::Node *FunctionsPluginOsg::EObjectPtrToOsgNodePtr(EObject *objPtr)
{
    osg::Node* osgNode = NULL;
    NodeOsg* nodeOsg = dynamic_cast<NodeOsg*>(objPtr);
    if(nodeOsg != NULL)
    {
        osg::ref_ptr<osg::Object> osgObj = nodeOsg->getObject();
        osgNode = dynamic_cast<osg::Node*>(osgObj.get());

    }
    return osgNode;
}
